import {removeToken} from '../utils/localstorg'


const SET_USER_NAME='SETUSERNAME'
const LOUGOUT='LOUGOUT'
const initState={
  usr:'',
  userId:''
}

export function user(state=initState,action){
  switch (action.type) {
    case SET_USER_NAME:
      return {...state,...action.payload}
    case LOUGOUT:
      return initState
    default:
      return state
  }
}

export function setName(user){
  return {type:SET_USER_NAME,payload:{usr:user.user,userId: user._id}}
}

export function logout() {
  removeToken()
  return {type:SET_USER_NAME}
}
